package com.example.fragment;

import com.example.tab02.DetailsActivity;
import com.example.tab02.R;
import com.example.tab02.filelist;
import com.example.tab02.myRecycleradatper;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class AddFragment extends Fragment {

	private List<filelist> mDatas;
	private  myRecycleradatper recycleAdapter;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		
		View view=inflater.inflate(R.layout.add_tab, container, false);
		mDatas =  new ArrayList<filelist>();
		filelist fl;
		String zt;
		for  (  int  i=0; i < 20; i++) {
			//zt="未阅读";
			fl= new  filelist( "item" +i);
			mDatas.add(fl);
		}

		recycleAdapter= new myRecycleradatper( view.getContext() ,mDatas);
		recycleAdapter.setOnItemClick(new myRecycleradatper.OnItemClickListener() {
			@Override
			public void OnItemClick(View v, int position, String id) {
				Context context = view.getContext();
				Intent intent = new Intent(context, DetailsActivity.class);
				/*传ID在Main2Activity接受*/
				intent.putExtra("id",id);
				startActivity(intent);
			}
		});
		RecyclerView recyclerView=(RecyclerView) view.findViewById(R.id.rv_list);
		LinearLayoutManager layoutManager =  new  LinearLayoutManager(view.getContext()  );
		recyclerView.setLayoutManager(layoutManager);
		//如果可以确定每个item的高度是固定的，设置这个选项可以提高性能
		recyclerView.setHasFixedSize( true );
		//创建并设置Adapter
		recyclerView.setAdapter(recycleAdapter);
		recyclerView.setItemAnimator( new DefaultItemAnimator());
		return view;
	}

}
